//
//  AddAddressViewController.m
//  bitcoin
//
//  Created by caiyajun on 2018/5/11.
//  Copyright © 2018年 比特币. All rights reserved.
//

#import "AddAddressViewController.h"
#import "ScanViewController.h"
@interface AddAddressViewController ()
@property (weak, nonatomic) IBOutlet UIView *addressView;
@property (weak, nonatomic) IBOutlet UITextField *addressTF;
@property (weak, nonatomic) IBOutlet UIView *nameView;
@property (weak, nonatomic) IBOutlet UITextField *nameTF;
@property (weak, nonatomic) IBOutlet UIButton *sureButton;

@end

@implementation AddAddressViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(scanAddressAction:) name:@"scanAddressNoti" object:nil];
    
    self.addressView.layer.borderColor = RGBColor(69, 72, 90).CGColor;
    self.addressView.layer.borderWidth = 1.0f;
    
    self.nameView.layer.borderColor = RGBColor(69, 72, 90).CGColor;
    self.nameView.layer.borderWidth = 1.0f;
    
    [_addressTF setValue:[UIColor colorWithHexString:@"#606378"] forKeyPath:@"_placeholderLabel.textColor"];
    [_nameTF setValue:[UIColor colorWithHexString:@"#606378"] forKeyPath:@"_placeholderLabel.textColor"];
    
    UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"arrowleft-icon"] style:UIBarButtonItemStylePlain target:self action:@selector(backAction:)];
    self.navigationItem.leftBarButtonItem = back;
    
    [self.sureButton setBackgroundImage:[UIImage imageWithColor:RGBColor(86, 54, 157)] forState:(UIControlStateHighlighted)];
}
- (void) scanAddressAction:(NSNotification *)notification{
    self.addressTF.text=notification.object;
    
    
}

- (void)backAction:(UIBarButtonItem *)sender {
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)scanAction:(id)sender {
    NSLog(@"scan>>>>>>>>>>>>>>>>>>");
    DLOG(@"去扫一扫");
    ScanViewController *vc = [[ScanViewController alloc] init];
    vc.pushType=@"addAddress";
    [self.navigationController pushViewController:vc animated:YES];
}

- (IBAction)submitAction {
    if (self.addressTF.text.length == 0 ) {
        
        [MBProgressHUD showError:@"请输入地址"];
        return;
        
    }
    if (self.nameTF.text.length == 0 ) {
        
        [MBProgressHUD showError:@"请输入别名"];
        return;
        
    }
    NSDictionary *param= @{@"currency_id":self.currency_id,
                           @"address":self.addressTF.text,
                           @"mark":self.nameTF.text,
                           };
    [LSRequestManager putRequestWithURL:HUOBI(@"api/withdraw/modAddress")
                                 params:param
                                success:^(NSDictionary *responseData) {
                                    if ([responseData[@"ret"] integerValue ] == 0) {
                                        
                                        [self.navigationController popViewControllerAnimated:YES];
                                        
                                    } else {
                                        [MBProgressHUD showError:responseData[@"msg"]];
                                    }
                                }
                                failure:^(NSError *error) {
                                    
                                }
                                showHUD:NO];
    
    
}
- (IBAction)dissmissAction:(UITapGestureRecognizer *)sender {
    [self.view endEditing:YES];
}


@end
